home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
tlx_sq15.zip
/
GLOBAL.SLT
< prev
next >
Wrap
Text File
|
1990-10-17
|
8KB
|
233 lines
//-----------------------------------------------------------
// GLOBAL.SL? Save global variables in Telix.
//
// Calling sequence:
// Read the variable "NAME", result in <variable string>:
// call ("GLOBAL","R","NAME",<variable string>);
// If "NAME" is not found, an empty string is returned.
// Write the string <variable string> into "NAME":
// call ("GLOBAL","W","NAME",<variable string>);
// If "NAME" can not be stored (not enough room) the variable
// will not be stored, and the script will return the code -1.
// Delete a variable:
// call ("GLOBAL","W","NAME",0); // (the "0" must be included)
// or call ("GLOBAL","D","NAME",0); // (the "0" may be omitted)
// In variable names, case is insignificant. The variables may be
// *any* string, except the length is limited to 80 characters
// The script can store up to 40 variables of length <=20 characters,
// and 10 variables of 20 < length <=80 characters,
// Make sure that the longest length you'll ever use is specified
// the first time you define a variable. Otherwise, if you want to
// modify a <20 char. variable to >20 characters, you must delete
// the original first.
// Author: Inge Vabekk
// Hamangskogen 108
// N-1300 SANDVIKA
// NORWAY
//-----------------------------------------------------------
str shortnames[240] // Table of names for 40 short strings
,longnames [60] // Table of names for 10 long strings
,shortstrings [840] // 40 strings of length 21
,longstrings [810] // 10 strings of length 81
,helpname [6] // Temporary for name
,spaces [6] // Store spaces.
,helpvar [81] // Temporary for string
; // with (room for terminating zero)
int next_short_entry=0
,next_long_entry=0
,max_short_entry=819 // Max. subscript in entry table
,max_long_entry=72 // Max. subscript in entry table
,namelen // Length of names
,longstringlen=81 // Length of strings.
,shortstringlen=21
,varlen // Length of current string.
,long // Long/short indocator
,get = 0 // Code to GET a variable.
,put = 1 // Code to PUT a variable.
;
//-----------------------------------------------------------
// Script starts here.
//-----------------------------------------------------------
main (str rwrite, str name, str varname)
{
int i, j;
namelen = strmaxlen(helpname);
varlen = strlen(varname);
for(i=0; i<namelen; ++i)
setchr(spaces,i,' ');
setchr(spaces,namelen,0);
if (rwrite=="R")
i = read (name,varname); // Read the value.
else if (rwrite=="W")
{ if (strlen(varname) < 1) // No name: Delete it.
i = write (name,"");
else
{ i = write (name,""); // Delete first, then
i = write (name,varname); // write this name.
}
}
else if (rwrite=="D")
i = write (name,"");
else if (rwrite=="L") // List all names.
{ prints ("ALL SHORT GLOBAL VARIABLES:");
for (i=j=0; i<next_short_entry; i=i+namelen)
{ substr (shortstrings,j,shortstringlen,helpvar);
substr (shortnames,i,namelen,helpname);
printsc(helpname);
printsc (":");
prints (helpvar);
j = j+shortstringlen;
}
prints ("ALL LONG GLOBAL VARIABLES:");
for (i=j=0; i<next_long_entry; i=i+namelen)
{ substr (longstrings,j,longstringlen,helpvar);
substr (longnames,i,namelen,helpname);
printsc(helpname);
printsc (":");
prints (helpvar);
j = j+longstringlen;
}
}
return (i); // Return with code.
}
//-----------------------------------------------------------
// Read a variable.
//-----------------------------------------------------------
read (str name, str varname)
{
move (name); // Move name to global
return (getput (0,varname)); // and read.
}
//-----------------------------------------------------------
// Write a variable.
//-----------------------------------------------------------
write(str name, str varname)
{
move (name); // Move name to global
return (getput (1,varname)); // and write.
}
//-----------------------------------------------------------
// Move name to global area.
//-----------------------------------------------------------
move(str name)
{
helpname = name; // Move name to global.
strupper(helpname); // Make upper characters
strcat (helpname,spaces); // fill with spaces
}
//-----------------------------------------------------------
// Read or write a name to or from the storage area.
//-----------------------------------------------------------
getput (int write, str varname)
{
int c, i, j, exist;
exist = strpos (longnames,helpname,0); // Check if name is in table.
if (exist >= 0)
long = 1;
else
{ long = 0;
exist = strpos (shortnames,helpname,0); // Check if name is in table.
}
if (exist < 0) // Non-existent?
{ if (!write) // Read?
{ varname = ""; // Yes. Nothing there.
return(-1);
}
long = varlen > 20;
if (long) // Add long variable
{ exist = strpos (longnames,spaces,0);// Deleted variable found?
if (exist >= 0) // Must be at correct position!
exist = ((exist+namelen-1)/namelen)*namelen;
else // No, expand table.
{ exist = next_long_entry;
next_long_entry = next_long_entry+namelen;
if (next_long_entry > max_long_entry) return (-1);
}
// Move all characters.
copychrs (helpname,longnames,exist,namelen);
}
else // Add short variable
{ exist = strpos (shortnames,spaces,0);// Deleted variable found?
if (exist >= 0) // Must be at correct position!
exist = ((exist+namelen-1)/namelen)*namelen;
else // No, expand table.
{ exist = next_short_entry;
next_short_entry = next_short_entry+namelen;
if (next_short_entry > max_short_entry) return (-1);
}
// Move all characters.
copychrs (helpname,shortnames,exist,namelen);
}
}
// "exist" contains start subscript for the variable name.
// "j" contains start subscript for its contents.
// "long"=1; Variable is in "longstrings
// "long"=0; Variable is in "shortstrings
if (long)
{ j = (exist/namelen)*longstringlen; // Find start position.
if (write) // Write?
{ if (strlen(varname)==0) // Yes. Delete?
copychrs (spaces // Write over with spaces.
,longnames,exist,namelen);
else
copystr (varname // Copy name.
,longstrings,j,longstringlen-1);
}
else // Read:
substr (longstrings // Copy variable.
,j,longstringlen,varname);
}
else
{ j = (exist/namelen)*shortstringlen; // Find start position.
if (write) // Write?
{ if (strlen(varname)==0) // Yes. Delete?
copychrs (spaces // Write over with spaces.
,shortnames,exist,namelen);
else
copystr (varname // Copy name.
,shortstrings,j,shortstringlen-1);
}
else // Read:
substr (shortstrings // Copy variable.
,j,shortstringlen,varname);
}
if (write) return (0);
for (i=strlen(varname)-1; i>0; --i)
{ if (subchr (varname,i) > ' ') break;
setchr (varname,i,